package spt.jukg.singleton.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.DispatcherServlet;

import com.alibaba.fastjson.JSONObject;

import spt.jukg.singleton.pojo.Student;
import spt.jukg.singleton.service.MainService;
import spt.jukg.singleton.util.RedisUtil;

import java.util.*;

import javax.servlet.http.HttpServlet;
@RestController
@RequestMapping("/main")
public class MainController {
	@Autowired
	private MainService mainService;
	
	@RequestMapping("/test/{pageNum}")
	public String getInfo(@PathVariable("pageNum") String pageNum) {
		List list=mainService.getInfo(pageNum);
		
		return JSONObject.toJSONString(list);
	}
	@RequestMapping("/redis/{key}/{value}")
	public String getInfo(@PathVariable("key")String key,@PathVariable("value") int value,Model model) {
		
		RedisUtil.set(key, value);
		return 
				JSONObject.toJSONString(RedisUtil.get(key))+
				JSONObject.toJSONString(RedisUtil.getList("info", Student.class))+JSONObject.toJSONString(model.asMap());
	}
	
}
